// swiper的初始化

var swiper = new Swiper(".mySwiper", {
    //配置调整
    spaceBetween: 0,  //两个轮播单位之间间隔
    centeredSlides: true,
    autoplay: {
        delay: 2000,
        disableOnInteraction: false,
    },
    pagination: {
        el: ".swiper-pagination",
        clickable: true,
    },
    navigation: {
        nextEl: ".swiper-button-next",
        prevEl: ".swiper-button-prev",
    },
});

//鼠标移入移出
let lis = document.querySelectorAll('.cft-menus li')
let imgs = document.querySelectorAll('.cft-menus li img')
function move() {
    lis.forEach((li, i) => {
        li.onmouseover = function () {
            console.log(imgs[i]);
            imgs[i].src = `./images/api0${i + 1}-c.svg`
            if (i === 8) {
                imgs[i].src = './images/apic1-c.svg'
            }
            if (i === 9) {
                imgs[i].src = './images/apic2-c.svg'
            }
            li.style.background = 'rgb(47,126,233)'
        }
        li.onmouseout = function () {
            console.log(imgs[i]);
            imgs[i].src = `./images/api0${i + 1}.svg`
            if (i === 8) {
                imgs[i].src = './images/apic1.svg'
            }
            if (i === 9) {
                imgs[i].src = './images/apic2.svg'
            }
            li.style.background = null
        }
    })
}

let imgss = document.querySelectorAll('.trademark img')
move()


//轮播图
let index = 0
let timerId = null;
let cons = document.querySelectorAll('.con')

timerId = setInterval(function () {
    cons[index].classList = 'con'
    index++
    if (index === 3) {
        index = 0
    }
    cons[index].classList = 'con on'
}, 2000)




let returnTop = document.querySelector('.return')
// 窗口滚动事件
function winScroll() {
    window.onscroll = () => {
        // 控制返回顶部的显示和隐藏
        if (this.window.scrollY >= 700) {
            returnTop.style.display = "block"
        } else {
            returnTop.style.display = "none"
        }
    }
}
winScroll()

//返回网页顶部
function returnTops() {
    returnTop.onclick = () => {
        let st = window.scrollY;//获取距离文档顶部的距离
        window.clearInterval(timerId);
        timerId = window.setInterval(function () {
            st -= 100;
            if (st <= 0) {
                st = 0;
                window.clearInterval(timerId)
            }
            window.scrollTo(0, st);

        }, 10)
    }
}
returnTops()

//点击跳转事件
let liss = document.querySelectorAll('.nav-item')
let login = document.querySelector('.login')
let register = document.querySelector('.register')
console.log(liss);
function skip() {
    liss.forEach((li, i) => {
        li.onclick = (() => {
            console.log(111);
            if (i === 0)
                window.location.replace('./index.html')
            if (i === 1)
                window.location.replace('./API.html')
            if (i === 2)
                window.location.replace('./customer.html')
        })
    })
    login.onclick = () => { location = './login.html' }
    register.onclick = () => { location = './register.html' }
}
skip()